import {
	createRouter,
	createWebHistory
} from 'vue-router'

const routes = [
	{
		path: '/',
		redirect: '/login'
	},
	{
		path: '/login',
		name: 'login',
		component: () => import('../views/login.vue')
	},
	{
		path: '/index',
		redirect: '/welcome',
		component: () => import('../views/index.vue'),
		children: [
		{
			path: '/welcome',
			component: () => import('../views/welcome.vue')
		},	
		{
			path: '/alist',
			component: () => import('../views/admin/alist.vue')
		},
		{
			path: '/hy',
			component: () => import('../views/hy.vue')
		},
		{
			path: '/ulist',
			component: () => import('../views/ulist.vue')
		},
		{
			path: '/carlist',
			component: () => import('../views/carlist.vue')
		},
		{
			path: '/nbdfd',
			component: () => import('../views/nbdfd.vue')
		},
		{
			path: '/jgdfd',
			component: () => import('../views/jgdfd.vue')
		},
		{
			path: '/hmname',
			component: () => import('../views/hmname.vue')
		},
		{
			path: '/shdw',
			component: () => import('../views/shdw.vue')
		},
		]
	}
]

const router = createRouter({
	history: createWebHistory(process.env.BASE_URL),
	routes
})

// 挂载路由导航守卫判断用户是否登录
router.beforeEach((to, from, next) => {
	if (to.path === '/login') return next()
	// 获取token
	const tokenStr = window.sessionStorage.getItem('token')
	if (!tokenStr) return next('/login')
	next()
})
export default router
